﻿using System.Globalization;

namespace RawInput;

public static class KeyMapper
{
    // I prefer to have control over the key mapping
    // This mapping could be loading from file to allow mapping changes without a recompile
    public static string GetKeyName(int value)
    {
        return value switch
        {
            0x41 => "A",
            0x6b => "Add",
            0x40000 => "Alt",
            0x5d => "Apps",
            0xf6 => "Attn",
            0x42 => "B",
            8 => "Back",
            0xa6 => "BrowserBack",
            0xab => "BrowserFavorites",
            0xa7 => "BrowserForward",
            0xac => "BrowserHome",
            0xa8 => "BrowserRefresh",
            170 => "BrowserSearch",
            0xa9 => "BrowserStop",
            0x43 => "C",
            3 => "Cancel",
            20 => "Capital",
            //case 20:      return "CapsLock";
            12 => "Clear",
            0x20000 => "Control",
            0x11 => "ControlKey",
            0xf7 => "Crsel",
            0x44 => "D",
            0x30 => "D0",
            0x31 => "D1",
            50 => "D2",
            0x33 => "D3",
            0x34 => "D4",
            0x35 => "D5",
            0x36 => "D6",
            0x37 => "D7",
            0x38 => "D8",
            0x39 => "D9",
            110 => "Decimal",
            0x2e => "Delete",
            0x6f => "Divide",
            40 => "Down",
            0x45 => "E",
            0x23 => "End",
            13 => "Enter",
            0xf9 => "EraseEof",
            0x1b => "Escape",
            0x2b => "Execute",
            0xf8 => "Exsel",
            70 => "F",
            0x70 => "F1",
            0x79 => "F10",
            0x7a => "F11",
            0x7b => "F12",
            0x7c => "F13",
            0x7d => "F14",
            0x7e => "F15",
            0x7f => "F16",
            0x80 => "F17",
            0x81 => "F18",
            130 => "F19",
            0x71 => "F2",
            0x83 => "F20",
            0x84 => "F21",
            0x85 => "F22",
            0x86 => "F23",
            0x87 => "F24",
            0x72 => "F3",
            0x73 => "F4",
            0x74 => "F5",
            0x75 => "F6",
            0x76 => "F7",
            0x77 => "F8",
            120 => "F9",
            0x18 => "FinalMode",
            0x47 => "G",
            0x48 => "H",
            0x15 => "HanguelMode",
            //case 0x15:    return "HangulMode";
            0x19 => "HanjaMode",
            0x2f => "Help",
            0x24 => "Home",
            0x49 => "I",
            30 => "IMEAceept",
            0x1c => "IMEConvert",
            0x1f => "IMEModeChange",
            0x1d => "IMENonconvert",
            0x2d => "Insert",
            0x4a => "J",
            0x17 => "JunjaMode",
            0x4b => "K",
            //case 0x15:    return "KanaMode";
            //case 0x19:    return "KanjiMode";
            0xffff => "KeyCode",
            0x4c => "L",
            0xb6 => "LaunchApplication1",
            0xb7 => "LaunchApplication2",
            180 => "LaunchMail",
            1 => "LButton",
            0xa2 => "LControl",
            0x25 => "Left",
            10 => "LineFeed",
            0xa4 => "LMenu",
            160 => "LShift",
            0x5b => "LWin",
            0x4d => "M",
            4 => "MButton",
            0xb0 => "MediaNextTrack",
            0xb3 => "MediaPlayPause",
            0xb1 => "MediaPreviousTrack",
            0xb2 => "MediaStop",
            0x12 => "Menu",
            // case 65536:  return "Modifiers";
            0x6a => "Multiply",
            0x4e => "N",
            0x22 => "Next",
            0xfc => "NoName",
            0 => "None",
            0x90 => "NumLock",
            0x60 => "NumPad0",
            0x61 => "NumPad1",
            0x62 => "NumPad2",
            0x63 => "NumPad3",
            100 => "NumPad4",
            0x65 => "NumPad5",
            0x66 => "NumPad6",
            0x67 => "NumPad7",
            0x68 => "NumPad8",
            0x69 => "NumPad9",
            0x4f => "O",
            0xdf => "Oem8",
            0xe2 => "OemBackslash",
            0xfe => "OemClear",
            0xdd => "OemCloseBrackets",
            0xbc => "OemComma",
            0xbd => "OemMinus",
            0xdb => "OemOpenBrackets",
            190 => "OemPeriod",
            220 => "OemPipe",
            0xbb => "Oemplus",
            0xbf => "OemQuestion",
            0xde => "OemQuotes",
            0xba => "OemSemicolon",
            0xc0 => "Oemtilde",
            80 => "P",
            0xfd => "Pa1",
            // case 0x22:   return "PageDown";
            // case 0x21:   return "PageUp";
            0x13 => "Pause",
            250 => "Play",
            0x2a => "Print",
            0x2c => "PrintScreen",
            0x21 => "Prior",
            0xe5 => "ProcessKey",
            0x51 => "Q",
            0x52 => "R",
            2 => "RButton",
            0xa3 => "RControl",
            //case 13:      return "Return";
            0x27 => "Right",
            0xa5 => "RMenu",
            0xa1 => "RShift",
            0x5c => "RWin",
            0x53 => "S",
            0x91 => "Scroll",
            0x29 => "Select",
            0xb5 => "SelectMedia",
            0x6c => "Separator",
            0x10000 => "Shift",
            0x10 => "ShiftKey",
            //case 0x2c:    return "Snapshot";
            0x20 => "Space",
            0x6d => "Subtract",
            0x54 => "T",
            9 => "Tab",
            0x55 => "U",
            0x26 => "Up",
            0x56 => "V",
            0xae => "VolumeDown",
            0xad => "VolumeMute",
            0xaf => "VolumeUp",
            0x57 => "W",
            0x58 => "X",
            5 => "XButton1",
            6 => "XButton2",
            0x59 => "Y",
            90 => "Z",
            0xfb => "Zoom",
            _ => value.ToString(CultureInfo.InvariantCulture).ToUpper(),
        };
    }

    // If you prefer the virtualkey converted into a Microsoft virtualkey code use this
    //public static string GetMicrosoftKeyName(int virtualKey)
    //{
    //    return new KeysConverter().ConvertToString(virtualKey);
    //}
}
